/**
 * 
 */
package com.quydat.forum.managedbeans;

import javax.ejb.EJB;

import com.quydat.forum.entites.UserEntity;
import com.quydat.forum.interfaces.UserEntityManageLocal;

/**
 * @author Dat
 * This managed bean presents login process of user
 */
public class Login {
	/**
	 * Injection user manage local
	 */
	@EJB
	private UserEntityManageLocal userManage;
	/**
	 * user entity
	 */
	private UserEntity user;
	/**
	 * loginName
	 */
	private String loginName;
	/**
	 * passWord
	 */
	private String password;
	
	public String getLoginName() {
		return loginName;
	}
	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	/**
	 * After login, the user is redirected to correesponding page
	 * @return
	 * login: user and password are invalid, user must login against
	 * 
	 */
	public String afterLogin()
	{
		user=userManage.getUserWithLoginNamePasword(loginName, password);
		//user and password are invalid
		if(user==null)
		{
			return "login";
		}
		else
		{
			return "success";
		}
	}
}
